package co.fitstart.api.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;

import co.fitstart.api.service.ProductService;
import co.fitstart.entity.product.Product;
import co.fitstart.entity.product.ProductCategory;
import co.fitstart.entity.product.Status;

/**
 *
 * @author mohanlan
 *
 */
@Service("productService")
public class ProductServiceImpl implements ProductService {

    @Autowired
    private GenericDaoSupport genericDaoSupport;

    /* (non-Javadoc)
     * @see co.fitstart.api.service.ProductService#listAvailableProduct()
     */
    @SuppressWarnings("unchecked")
    public List<Product> listAvailableProduct() {
        String sentence = "FROM Product product WHERE product.disabled = false AND product.display = true AND product.buyable = true AND product.status = :status";
        return genericDaoSupport.searchForList(sentence, "status", Status.ONLINE);
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.api.service.ProductService#loadProduct(java.lang.Long)
     */
    public Product loadProduct(Long productId) {
        return genericDaoSupport.load(Product.class, productId);
    }

    /* (non-Javadoc)
     * @see co.fitstart.api.service.ProductService#listProductCategories()
     */
    @SuppressWarnings("unchecked")
    public List<ProductCategory> listProductCategories() {
        String querySentence = "FROM ProductCategory productCategory WHERE productCategory.disabled = false";
        return genericDaoSupport.searchForList(querySentence);
    }

}
